﻿
@{
    ViewBag.Title = "我的订单";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}
@section head{
    <link rel="stylesheet" type="text/css" href="~/Content/WxPage.css?d=@DateTime.Now" />
    @Scripts.Render("~/bundles/jquery")
    <script src="~/Scripts/bootstrap.js"></script>


}

<h2>我的订单</h2>
<hr  style="margin-top:0;margin-bottom:5px;"/>
@for (int i = 0; i < ViewBag.OrderList.Count; i++)
{
    <div class="orderList">
        <p style="padding-top:10px;">订单编号:No @ViewBag.OrderList[i]["ZZOrderId"]   下单时间：@ViewBag.OrderList[i]["OrderTime"]</p>
        <hr style="margin-top:0;margin-bottom:5px;" />
        <p>酒店名：无隅.@ViewBag.OrderList[i]["HotelName"] &nbsp;&nbsp;&nbsp;房型：@ViewBag.OrderList[i]["RoomTypeName"]</p>
        <p>入住时间:@ViewBag.OrderList[i]["EnterTime"] &nbsp;&nbsp;&nbsp;离店时间:@ViewBag.OrderList[i]["LeaveTime"]</p>
        <p>一共 @ViewBag.OrderList[i]["DiffDay"]晚&nbsp;&nbsp;&nbsp;房间数量：@ViewBag.OrderList[i]["RoomNum"]间</p>
        <p>旅客联系电话:@ViewBag.OrderList[i]["PhoneNum"]</p>
        <p>一共价格:@ViewBag.OrderList[i]["TotalPrice"]RMB &nbsp;&nbsp;&nbsp;状态：@ViewBag.OrderList[i]["Orderstate"]</p>
        @if (@ViewBag.OrderList[i]["state"] == 0)
        {
            <div style="float:left;width:70%;height:30px;background-color:limegreen;" onclick="WxPay(@ViewBag.OrderList[i]["ZZOrderId"])">
                <p style="line-height:30px;font-size:25px;text-align:center;">微信付款</p>
            </div>
            <div style="float:left;width:30%;height:30px;background-color:cadetblue;" onclick="CancelOrder(@ViewBag.OrderList[i]["HotelId"],@ViewBag.OrderList[i]["ZZOrderId"])">
                <p style="line-height:30px;font-size:25px;text-align:center;">取消订单</p>
            </div>
            <p style="display:block;clear:both;margin:0;"></p>
        }
    </div>
    <p></p>
}

<script type="text/javascript">
    /*小本生意，请黑客大牛不要来破解我，在此谢过！！！*/

    var wxJsApiParam = "";

    function jsApiCall() {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            $.parseJSON(wxJsApiParam),//josn串
            function (res) {
                WeixinJSBridge.log(res.err_msg);
                alert(res.err_code + res.err_desc + res.err_msg);
            }
        );
    }
    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }

    function CancelOrder(hotelId, OrderId) {
        $.ajax({
            type: "POST",
            url: "/WxPage/CancelOrder",
            async: false,
            data: { "OrderId": OrderId, "hotelId": hotelId },
            success: function (msg) {
                if (msg == 1) {
                    //正确返回，执行操作                    
                    top.location = '/WxPage/OrderList';
                }else {
                    alert("订单取消失败，请联系酒店前台");
                    return;
                }
            }
        });
    }

    function WxPay(ZZOrderId) {
        $.ajax({
            type: "POST",
            url: "/WxPage/WxPay",
            async: false,
            data: { "ZZOrderId": ZZOrderId},
            success: function (msg) {
                if (msg.err == "ok") {
                    //正确返回，执行操作                    
                    wxJsApiParam = msg.Param;
                    callpay();

                } else if (msg.err == "NoCookies"){
                    top.location = '/WxPage/Index';
                } else if (msg.err == "errId") {
                    alert("用户错误，请重新登陆");
                    top.location = '/WxPage/Register';
                } else if (msg.err == 'errOrderId') {
                    alert("订单号错误，不要试图错误提交,哥在后台做了验证的");
                    top.location = '/WxPage/Index';
                }
                else {
                    alert("订单提交失败，请联系酒店前台" + mes.err);
                    return;
                }
            }
        });
    }



</script>










<div id="menu" class="Wx_BottomMenu">
    <div id="HomePage" class="subMenu" onclick="JavaScript:window.location.href='/WxPage/MainView'">
        <p style="display:table-cell;vertical-align:middle;margin:0px;font-family:'Microsoft YaHei','微软雅黑';font-size:16px;color:rgb(127,127,127);">首&nbsp;&nbsp;页</p>
    </div>
    <div id="Rent" class="subMenu" style="border-left-width:0px;width:34%;" onclick="JavaScript:window.location.href='/WxPage/Index'">
        <p style="display:table-cell;vertical-align:middle;margin:0px;font-family:'Microsoft YaHei','微软雅黑';font-size:16px;color:rgb(127,127,127);">预&nbsp;&nbsp;订</p>
    </div>
    <div id="Mine" class="subMenu" style="border-right-width:0px;border-left-width:0px;" onclick="JavaScript:window.location.href='/WxPage/Mine'">
        <p style="display:table-cell;vertical-align:middle;margin:0px;font-family:'Microsoft YaHei','微软雅黑';font-size:16px;color:rgb(127,127,127);">微&nbsp;&nbsp;信&nbsp;&nbsp;会&nbsp;&nbsp;员</p>
    </div>
</div>

